#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <rclcpp/rclcpp.hpp>
#include <rviz_common/panel.hpp>

#include <muduo/net/EventLoopThread.h>

#include <interface/msg/event.hpp>

namespace muduo {
namespace net {
class EventLoopThread;
}
}

namespace Ui {
class Form;
}

class QLabel;

namespace ui {
class EventPlugin : public rviz_common::Panel {
    Q_OBJECT

public:
    EventPlugin(QWidget* parent = nullptr);
    ~EventPlugin();

private:
    void rosInit(void);
    void onEvent(std::shared_ptr<interface::msg::Event>);
    void onTimer(void);
    void drawEventTitle(void);

private:
    Ui::Form* ui;
    QLabel* label;

    std::shared_ptr<muduo::net::EventLoopThread> eventLoopThread_ { nullptr };
    std::shared_ptr<rclcpp::Subscription<interface::msg::Event>> eventSubscriber_ { nullptr };
    std::shared_ptr<rclcpp::Node> node_ { nullptr };
    std::shared_ptr<rclcpp::TimerBase> timer_ { nullptr };
    // 前方,右前方,右方,右后方,后方,左后方,左方,左前方
    std::atomic<bool> eventDirectFlags_[8] { false };
    std::atomic<size_t> eventCounter_ { 0 };
};
} // namespace rvzi_plugin_demo

#endif // WIDGET_H
